package com.ruiysoft.crm.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.ruiysoft.crm.entity.SysDepartment;
import com.ruiysoft.crm.entity.Valuelist;
import com.ruiysoft.crm.mapper.SysDepartmentMapper;
import com.ruiysoft.crm.mapper.ValuelistMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Yanghu
 * @since 2018-08-11
 */
@RestController
@RequestMapping("department")
public class DepartmentController {
    @Autowired
    SysDepartmentMapper sysDepartmentMapper;

    @Cacheable("queryByEnterpriseId")
    @GetMapping("queryByEnterpriseId")
    public Object queryByEnterpriseId(String enterpriseId) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("success", false);

        try {
            List<SysDepartment> list = sysDepartmentMapper.selectList(new EntityWrapper<SysDepartment>().eq("enterpriseId", enterpriseId));
            if(list.size() > 0) {
                map.put("success", true);
                map.put("data", list);
            }
            else
                map.put("errorMsg", "查询数据失败");

        } catch (Exception error) {
            map.put("errorMsg", "delete 异常: " + error.getMessage());
        }

        return map;
    }

}
